import request from '@/utils/request'
import type {
  CategoryResponseData,
  AttrInfoResponseData,
  AttrObj,
} from './type'

const API = {
  Category1_URL: '/admin/product/getCategory1',
  Category2_URL: '/admin/product/getCategory2/',
  Category3_URL: '/admin/product/getCategory3/',
  ATTRINFO_URL: '/admin/product/attrInfoList/',
  ADDOREDITATTR_URL: '/admin/product/saveAttrInfo',
  DELETEATTR_URL: '/admin/product/deleteAttr/',
}

export const reqCategory1 = async () => {
  return await request.get<any, CategoryResponseData>(API.Category1_URL)
}

export const reqCategory2 = async (id: number | string) => {
  return await request.get<any, CategoryResponseData>(
    API.Category2_URL + String(id),
  )
}

export const reqCategory3 = async (id: number | string) => {
  return await request.get<any, CategoryResponseData>(
    API.Category3_URL + String(id),
  )
}

export const reqAttrInfoList = async (
  c1Id: string | number,
  c2Id: string | number,
  c3Id: string | number,
) => {
  return await request.get<any, AttrInfoResponseData>(
    API.ATTRINFO_URL + `${c1Id}/${c2Id}/${c3Id}`,
  )
}

export const reqAddOrEditAttr = async (data: AttrObj) => {
  return await request.post<any, any>(API.ADDOREDITATTR_URL, data)
}

export const reqDeleteAttr = async (attrId: number) => {
  return await request.delete<any, any>(API.DELETEATTR_URL + attrId)
}
